#include <application.h>
#include <system/render_system.h>
#include <GLFW/glfw3.h>
#include <utl/async.h>
#include <gfx/dx12/core.h>
#include <system/window_system.h>
#include <system/scene_system.h>
#include <gui/GuiBase.h>
#include <qmainwindow.h>

namespace
{
	static struct
	{
		int argc;
		char** argv;
		Application* app;
	}global{};
}

Application::Application() :
	q_app{ global.argc,global.argv }
{
	global.app = this;
	utl::async_initialize();
	primal::gfx::initialize();
	
	this->main_window = primal::GetWS().CreateWnd("Render Surface", 1280, 720);

	/*primal::gui::initialize(main_window.get());
	primal::gui::set_theme_blender();
	primal::render_system_initialize(main_window.get());
	primal::scene_initialize();*/
}

Application::~Application()
{
	primal::gfx::shutdown();
	utl::async_shutdown();
	global.app = nullptr;
}

Application& Application::Instance()
{
	return *global.app;
}

void Application::run()
{
	/*while (!glfwWindowShouldClose(main_window.get()))
	{
		glfwPollEvents();
		primal::tick(0.1f);
		primal::render_system_render();
	}*/

	QMainWindow mw{};
	mw.show();
	this->q_app.exec();
}